<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.gameName" placeholder="输入游戏名称" style="width: 200px;" />
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查询</el-button>
      <el-button class="filter-item" icon="el-icon-plus" @click="routeToPath('/games/add')">新增</el-button>
    </div>
    <el-table v-loading="loading" :data="data" size="small" border style="width: 100%;">
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <div>{{ scope.$index+(listQuery.page - 1) * listQuery.size + 1 }}</div>
        </template>
      </el-table-column>
      <el-table-column label="游戏名称" align="center">
        <template slot-scope="scope">
          <div>{{ scope.row.gameName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="游戏图标" align="center">
        <template slot-scope="scope">
          <div> <img class="maxs" :src="URL.PIC+scope.row.gameIcon"> </div>
        </template>
      </el-table-column>
      <el-table-column label="配置名称" align="center">
        <template slot-scope="scope">
          <div>{{ scope.row.configName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="是否显示" align="center">
        <template slot-scope="scope">
          <div>
            <el-switch v-if="scope.row.showFlag == 0"
            @change="changeShow(scope.row, true)"
            :value="false"/>
            <el-switch v-else
            @change="changeShow(scope.row, false)"
            :value="true"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center">
        <template slot-scope="scope">
          <span>{{ fmtDate(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新日期" align="center">
        <template slot-scope="scope">
          <span>{{ fmtDate(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180px" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="edit(scope.row.id)">编辑</el-button>
          <el-button type="danger" size="mini" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pages'
import { list, del, show } from '@/api/business/games'
export default {
  name: '',
  components: {
    Pagination,
  },
  data() {
    return {
      loading: false,
      total: 0,
      data: null,
      configId: null,
      listQuery: {
        gameName: null,
        page: 1,
        size: 10
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      list(this.listQuery).then(res=>{
        this.data = res.content.content
        this.total = res.totalElements
      })
    },
    changeShow(item, showFlag) {
      show({id: item.id, show: showFlag}).then(res=>{
        this.getList()
      })
    },
    handleFilter() {
      this.getList()
    },
    del(id) {
      this.$alert('是否确定删除？', '提示', {
        confirmButtonText: '确定',
        type: 'warning',
        callback: action => {
          if(action == 'confirm'){
            del(id).then(res=>{
              this.actionsAfter('删除成功！', 'success');
              this.getList();
            })
          }
        }
      });
    },
    edit(id) {
      for (var i in this.data) {
        if(this.data[i].id == id){
          this.setlocalStorage('bGames', this.data[i]);
          this.routeToPath('/games/add?id='+id);
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
